package org.paradise.dms.web.action.student;

import java.util.List;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.directwebremoting.annotations.RemoteProxy;
import org.paradise.dms.pojo.CollegeInfo;
import org.paradise.dms.pojo.MajorInfo;
import org.paradise.dms.services.StudentService;
import org.paradise.dms.web.action.DMSBaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RemoteProxy(name = "dWRCollegeMajorAction")
public class DWRCollegeMajorAction extends DMSBaseAction {
	private static Logger log = Logger.getLogger(DWRCollegeMajorAction.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 8522307267917018445L;
	@Autowired
	private StudentService studentService;
	private List<CollegeInfo> collegeInfoList;
	private List<MajorInfo> majorInfoList;

	public JSONArray getAllCollegeInfo() {
		collegeInfoList = studentService.getAllcollegeInfo();
		log.info(collegeInfoList.get(1).getCollegeinfoname());
		if (collegeInfoList != null & collegeInfoList.size() > 0) {
			JSONArray jsonArray = JSONArray.fromObject(collegeInfoList);
			return jsonArray;
		}
		return null;
	}

	public JSONArray getAllMajorInfo() {

		majorInfoList = studentService.getAllMajorInfo();
		if (majorInfoList != null & majorInfoList.size() > 0) {
			JSONArray jsonArray = JSONArray.fromObject(majorInfoList);
			return jsonArray;
		}
		return null;
	}

	public JSONArray getMajorInfoByCollegeId(String collegeinfoid) {
		majorInfoList = studentService.getMajorInfoByCollegeId(collegeinfoid);
		if (majorInfoList != null & majorInfoList.size() > 0) {
			JSONArray jsonArray = JSONArray.fromObject(majorInfoList);
			return jsonArray;
		}
		return null;

	}

	public JSONArray getCollegeInfoByMajorId(String majorinfoid) {
		collegeInfoList = studentService.getCollegeInfoByMajorId(majorinfoid);
		if (collegeInfoList != null & collegeInfoList.size() > 0) {
			JSONArray jsonArray = JSONArray.fromObject(collegeInfoList);
			return jsonArray;
		}
		return null;
	}
	public boolean insertCollege(String collegename){
		return  studentService.insertCollege(collegename);
	}
	public boolean deleteCollege(int collegeid){
		return studentService.deleteCollege(collegeid);
	}
	public int updateCollege(int collegeid,String collegename){
		return studentService.updateCollege(collegeid,collegename);
	}
	public boolean insertMajor(int collegeid,String majorname){
		return studentService.insertMajor(collegeid,majorname);
	
	}
	public boolean deleteMajor(int majorid){
		return studentService.deleteMajor(majorid);
	}
	public int updateMajor(int majorid,String majorname){
		return studentService.updateMajor(majorid,majorname);
	}

}
